package ae_game;

import java.io.*;
import java.util.Vector;

public class SettingsLoader
{
	private static File file;
	private static PrintStream out; 
	private static BufferedReader in;
	
	
	public static Vector<String> hosts = new Vector<String>();
	
	public SettingsLoader()
	{
		String temp;
		file = new File("settings.cfg");
		try
		{
			if(file.exists())
			{
				in = new BufferedReader( new FileReader(file));
				while(true)
				{
					temp=in.readLine();
					if(temp==null)// end of stream reached
						break;
					if(temp.equals("[HOSTS]"))
					{
						temp=in.readLine();
						while(!temp.equals("[/HOSTS]"))
						{
							hosts.add(temp);
							temp=in.readLine();
						}
					}
				}
			} 
		}
		catch (IOException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	static public void SaveSettings()
	{
		file.delete();
		try
		{
			file.createNewFile();
			out = new PrintStream(file);
			
		} catch (FileNotFoundException e)
		{
			e.printStackTrace();
		} catch (IOException e)
		{
			e.printStackTrace();
		}
		out.println("[HOSTS]");
		for(int i=0; i<hosts.size(); ++i)
		{
			out.println(hosts.get(i));
		}
		out.println("[/HOSTS]");
		
		out.close();
	}
}
